package org.dydl.controller.system;

import org.dydl.common.dto.ResponseMessage;
import org.dydl.model.system.SysEmployee;
import org.dydl.service.system.ISysEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 职员管理Controller
 *
 * @author Jack
 */
@RestController
@RequestMapping("/api/employee")
public class EmployeeController {

	 @Autowired
	 private ISysEmployeeService sysEmployeeService;
	// @Autowired
	// private ISysEmployeeDepartService employeeDepartService;
	// @Autowired
	// private ISysDepartService departService;
	// @Autowired
	// private ISysUserService sysUserService;
	// @Autowired
	// private ISysRoleService sysRoleService;

	 
		/**
		 * 添加新职员
		 *
		 * @param employee
		 */
		@RequestMapping("/save")
		public void save(@RequestBody SysEmployee employee) {

			ResponseMessage res =  sysEmployeeService.save(employee);
			if(res.getSuccess()){
				
			}
		}
		
		/**
		 * 分页、条件、查询职员
		 *
		 * @return the list
		 */
		@RequestMapping("/list")
		public ResponseMessage getEmployee(int page, int rows, String name) {
			ResponseMessage res = sysEmployeeService.getSysEmployeeList(page, rows, name);
			return res;
		}
		
		
		/**
		 * 删除职员
		 * 
		 * @param ids
		 * @return
		 */
		@RequestMapping("/delEmployee")
		public boolean delete(int[] ids) {
			if (ids.length != 0) {
				for (int i = 0; i < ids.length; i++) {
					sysEmployeeService.delete(ids[i]);
				}
				return true;
			} else {
				return false;
			}
		}

		
		/**
		 * 更新职员
		 *
		 * @param role
		 *            the role
		 * @return the long
		 */
		@RequestMapping("/update")
		public void update(@RequestBody SysEmployee employee) {
			sysEmployeeService.save(employee);
		}
		
		
		
		
}







/* 
*//**
* 分页查询职员信息 keyword 搜索条件姓名
*
* @param page
* @param rows
* @param
* @return
*//*

@RequestMapping("/list")
public ResponseMessage list(int page, int rows, String name) {
	// // 查询行数
	// Search search = new Search();
	// search.setPage(page - 1);
	// search.setMaxResults(rows);
	// if (null != name && !name.isEmpty()) {
	// search.addFilterEqual("name", name);
	// }
	// ResponseMessage msg = employeeService.search(search);
	// ResponseData<?> respData = (ResponseData<?>) msg.getData();
	// List<SysEmployee> employeeList = (List<SysEmployee>) respData.getList();
	// List<SysEmployeeExt> el = new ArrayList<>();
	// SysDepart depart;
	// SysUser user;
	// for (SysEmployee employee : employeeList) {
	// search.clear();
	// search.addFilterEqual("employeeId", employee.getId());
	// SysEmployeeExt e = new SysEmployeeExt();
	// BeanUtils.copyProperties(employee, e);
	// List<SysUser> sysUserList = (List<SysUser>)
	// sysUserService.search(search).getData();
	// if (sysUserList.size() > 0) {
	// user = sysUserList.get(0);
	// e.setUserId(user.getId());
	// e.setOriginalUserId(user.getId());
	// e.setUsername(user.getUserName());
	// }
	// List<SysDepart> sysDepartList = (List<SysDepart>)
	// employeeService.getDepartByEmplyeeId(employee.getId())
	// .getData();
	// if (sysDepartList.size() > 0) {
	// depart = sysDepartList.get(0);
	// e.setDepartID(depart.getDepartID());
	// e.setDepartMemoTX(depart.getMemo_TX());
	// e.setDepartName(depart.getDepartName());
	// }
	// el.add(e);
	// }
	// ResponseData<SysEmployeeExt> rd = new ResponseData<SysEmployeeExt>();
	// BeanUtils.copyProperties(respData, rd, "list");
	// rd.setList(el);
	// msg.setData(rd);
	// return msg;
	return new ResponseMessage(false);
}

*//**
* 根据id 获取所属组织机构名称和ID
*
* @param id
* @return
*//*
@RequestMapping("/getOrgName")
public Map<String, Object> getOrgName(int id) {
	// List<SysDepart> sysDepartList = (List<SysDepart>)
	// employeeService.getDepartByEmplyeeId(id).getData();
	// Map<String, Object> data = new HashMap<>();
	// if (sysDepartList.size() > 0) {
	// data.put("org_name", sysDepartList.get(0).getDepartName());
	// data.put("orgId", sysDepartList.get(0).getDepartID());
	// } else {
	// data.put("org_name", "");
	// data.put("orgId", "");
	// }
	// return data;
	return null;
}



*//**
* 根据职员id 获取 所属机构名称
*
* @param id
*            职员id
*//*
@RequestMapping("/depaertInfo")
public ResponseMessage getDepaertByEmployeeId(int id) {
	ResponseMessage responseMessage = new ResponseMessage();

	// // 查询行数
	// Search search = new Search();
	// if (id != 0) {
	// search.addFilterEqual("employeeID", id);
	// }
	// List<SysEmployeeDepart> list = (List<SysEmployeeDepart>)
	// employeeService.search(search).getData();
	// if (list.size() == 0) {
	// return null;
	// } else {
	// // 根据id获取 所属机构信息
	// int epartId = list.get(0).getDepartID();
	// List<SysDepart> s = (List<SysDepart>) departService.find(epartId).getData();
	// responseMessage.setData(s.get(0));
	// responseMessage.setStatus(200);
	// responseMessage.setMsg("success");
	// responseMessage.setSuccess(true);
	// return responseMessage;
	// }
	return responseMessage;

}

*//**
* 根据职员id查询用户信息
*
* @param id
*            职员id
*//*
@RequestMapping("/userInfo")
public ResponseMessage getUserInfo(int id) {
	ResponseMessage responseMessage = new ResponseMessage(true);
	// List<SysUser> sysUserList = (List<SysUser>) sysUserService.search(new
	// Search().addFilterEqual("id", id)).getData();
	// // 查询所有角色信息
	// List<SysRole> sysRoleList = (List<SysRole>)
	// sysRoleService.search(null).getData();
	// Map<String, Object> map = new HashMap<String, Object>();
	// map.put("sysRoleList", sysRoleList);
	// if (sysUserList.size() > 0) {
	// map.put("sysUser", sysUserList.get(0));
	// }
	//
	// responseMessage.setData(map);
	return responseMessage;
}

*//**
* 更新用户信息
*
* @param user
*            the user
*//*
@RequestMapping("/saveOrUpData")
public boolean saveOrUpDate(SysUser user, int[] selected) {
	// // MD5加密 如果 密码没有为空则设置默认密码为6个0
	// List<SysUser> sysUserList = (List<SysUser>) sysUserService
	// .search(new Search().addFilterEqual("userName",
	// user.getUserName())).getData();
	// if (sysUserList.size() > 0) {
	// // 如果大于零账号不能重复返回false
	// return false;
	// } else {
	// if (user.getPassword() == null || "".equals(user.getPassword())) {
	// user.setPassword(MD5.encode("000000".getBytes()));
	// } else {
	// user.setPassword(MD5.encode(user.getPassword().getBytes()));
	// }
	// user.setStatus(true);
	// List<SysRole> sysRoleList = new ArrayList<SysRole>();
	// for (int el : selected) {
	// sysRoleList.add(new SysRole(el));
	// }
	//
	// user.setRoles(sysRoleList);
	// sysUserService.save(user);
	// }
	return true;
}

*//**
* 修改职员信息
*
* @param id
* @param name
* @param telNo
* @param create_TM
* @param gender
* @param orgId
* @return
*//*
@RequestMapping("/update")
public ResponseMessage save(@RequestBody SysEmployeeExt e) {
	//
	// SysEmployee employee = (SysEmployee) e;
	// SysUser user;
	//
	// if (e.getOriginalUserId() != null) {
	// user = ((List<SysUser>) sysUserService.search(new
	// Search().addFilterEqual("id", e.getOriginalUserId()))
	// .getData()).get(0);
	// user.setEmployeeId(0);
	// sysUserService.save(user);
	// }
	// if (employee.getId() == null) {
	// employee.setCreate_TM(new Date());
	// }
	// ResponseMessage msg = employeeService.save(employee, e.getDepartID());
	// if (!msg.getSuccess()) {
	// return msg;
	// }
	// if (e.getUserId() != null) {
	// user = ((List<SysUser>) sysUserService.search(new
	// Search().addFilterEqual("id", e.getUserId())).getData())
	// .get(0);
	// user.setEmployeeId(e.getId() != null ? e.getId() :
	// Integer.valueOf(msg.getData().toString()));
	// msg = sysUserService.save(user);
	// }
	// return msg;
	return new ResponseMessage(false);

}

*//**
* 删除职员信息
*
* @param ids
*//*
@RequestMapping("/delEmployee")
public Boolean deleteEmployee(int id) {
	// // 同时删除 关联表中的数据
	// if (null != ids && ids.length > 0) {
	// for (int i = 0; i < ids.length; i++) {
	// // 删除成功返回1
	// employeeService.removeById(ids[i]);
	// employeeDepartService.removeById(ids[i]);
	// }
	// return true;
	// } else {
	// return false;
	// }
	
	sysEmployeeService.delete(id);
	return false;

}
*/
